package com.itheima.sc.service.sms;


import cn.hutool.core.convert.Convert;
import com.itheima.sc.api.sms.SmsHomeNewProductApi;
import com.itheima.sc.pojo.sms.HomeNewProduct;
import com.itheima.sc.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SmsHomeNewProductService {

    @DubboReference
    private SmsHomeNewProductApi newProductApi;

    //添加新鲜好物的数据
    public void addNewProduct(List<HomeNewProduct> newProducts) {
        newProductApi.addNewProducts(newProducts);
    }

    //批量删除好物新品
    public void deleteNewProducts(List<Long> ids) {
        newProductApi.deleteNewProducts(ids);
    }

    //分页查询新品好物
    public PageResult selectNewProductList(Map<String, String> param) {
        String productName = param.get("productName");
        Integer page = Convert.toInt(param.get("pageNum"));
        Integer pageSize = Convert.toInt(param.get("pageSize"));
        Integer recommendStatus = Convert.toInt(param.get("recommendStatus"));
        return newProductApi.selectNewProductList(page, pageSize, recommendStatus,productName);
    }
    //批量修改首页推荐的新鲜好物的状态
    public void updateNewProductStatus(List<Long> ids, Integer status) {
        newProductApi.updateNewProductStatus(ids,status);
    }
    //修改推荐好物排序
    public void updateNewProductSort(Long id, Integer sort) {
        HomeNewProduct newProduct=new HomeNewProduct();
        newProduct.setId(id);
        newProduct.setSort(sort);
        newProductApi.updateNewProductSort(newProduct);
    }
}
